package org.geektimes.configuration.demo;


import org.geektimes.projects.user.web.model.GiteeConstants;

import java.io.*;
import java.net.URLEncoder;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;

/**
 * @Author: jipeng
 * @Description:
 * @Date: Created in 2021/3/12 9:36
 */
public class PreferencesDemo {

    public static void main(String[] args) throws BackingStoreException, UnsupportedEncodingException {

//        Preferences preferences = Preferences.userRoot();
//        preferences.put("my-key","Hello,Word");
//        preferences.flush();
//
//        System.out.println(preferences.get("my-key","1111"));

        String oauthPath = "https://gitee.com/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code";
        String callbackUrl = URLEncoder.encode(GiteeConstants.callbackUrl, "UTF-8");
        String path = String.format(oauthPath, GiteeConstants.clientId, callbackUrl);

        System.out.println(path);

//
//        ClassA a = new ClassA();
//        a.setId(1);
//
//
//        ClassB b = new ClassB();
//        b.setId(1);
//        b.setA(a);
//
//
//        try {
//            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
//            ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
//            objectOutputStream.writeObject(b);
//            byte[] bytes = byteArrayOutputStream.toByteArray();
//
//            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
//            ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
//
//            b = (ClassB) objectInputStream.readObject();
//
//            System.out.println(String.format("old a hashCode : %s；new a hashCode : %s, old a  equals new a:%s ",
//                    a.hashCode(), b.getA().hashCode(), a.equals(b.getA())));
//
//        } catch (Exception e) {
//            System.out.println(e.getMessage());
//        }
    }

}
